package com.gitee.ywj1352.jdk8;

/**
 * @author wenjie.yang
 * @date 2/24/2020 3:06 PM
 */
public class FinallyDemo {

    // 双重检查
    private static volatile FinallyDemo singleton;
    private FinallyDemo() {
    }
    public static FinallyDemo getSingleton() {
        if (singleton == null) {
            synchronized (FinallyDemo.class) {
                if (singleton == null) {
                    singleton = new FinallyDemo();
                }
            }
        }
        return singleton;
    }

    public static FinallyDemo getSingletonInner(){
        return FinallyDemoBuilder.singletonInner;
    }

    public static void main(String[] args) {
        //Basic RU1FQVxNU0QuRDJpLkN1c3RQb3J0YWw6VyFudDNyJTYwNQ==
        //Basic RU1FQVxNU0QuRDJpLkN1c3RQb3J0YWw6VyFudDNyNQ==
        fun1();
        FinallyDemo singleton = FinallyDemo.getSingletonInner();
        FinallyDemo singleton1 = FinallyDemo.getSingletonInner();
        System.out.println(singleton == singleton1);
    }



    //静态内部内 来创建 单例模式
    static class FinallyDemoBuilder{
        private static FinallyDemo singletonInner = new FinallyDemo();
    }


    public static void fun1() {
        try {
            System.out.println("  111111111111111111111 ");
            return;
        } catch (Exception e) {
        } finally {
            System.out.println("  finally ");
        }
    }
}
